package com.scorekeeper.ui;

import java.util.Map;

import com.scorekeeper.R;
import com.scorekeeper.objects.Team;
import com.scorekeeper.utils.Loader;
import com.scorekeeper.utils.TeamListAdapter;

import android.app.ListActivity;
import android.content.Intent;
import android.os.Bundle;
import android.view.View;
import android.widget.AdapterView;
import android.widget.AdapterView.OnItemClickListener;
import android.widget.AdapterView.OnItemLongClickListener;
import android.widget.ListView;

public class LeagueStandings extends ListActivity {
	
	@Override
    public void onCreate(Bundle savedInstanceState) {
		super.onCreate(savedInstanceState);
		setContentView(R.layout.nhl_standings);
		 
		ListView lv = getListView();
		lv.setChoiceMode(ListView.CHOICE_MODE_SINGLE);
		
		Map<Long, Team> sortedTeams = Loader.sortTeamsMapByPoints((new Loader()).loadTeams());
		final TeamListAdapter tla = new TeamListAdapter(this, R.layout.standing_item, sortedTeams);
		setListAdapter(tla);
		
		lv.setOnItemClickListener(new OnItemClickListener() {
	            public void onItemClick(AdapterView<?> parent, View view,
	                            int position, long id) {
	            	tla.setSelectedPosition(position);
	            }
	    });
		
		lv.setOnItemLongClickListener(new OnItemLongClickListener() {
	            public boolean onItemLongClick(AdapterView<?> parent, View view,
	                            int position, long id) {
	            		
	                    Intent myIntent = new Intent();
	                    myIntent.putExtra("teamId", tla.getItemId(position));
	                    
	                    
	                    
	                    //myIntent.setClassName("com.hyperzsoft.budget", "com.hyperzsoft.budget.ExpenseEdit");
	                    //startActivityForResult(myIntent, getResources().getInteger(R.integer.request_code_edit_expense));
	                    return false;
	            }
	    });
	}
	
	@Override
	public void onListItemClick(ListView l, View v, int position, long id) {
		//
	}
}